var url = "ws://localhost:8080/socket";

var socket = new WebSocket(url);

socket.onclose = function (p1) {
    console.log("Close")
}

socket.onopen = function (event) {
    console.log("Open");
    saySome();
}

socket.onmessage = function (p1) {
    console.log("Received:"+p1.data);
    setTimeout(function () {
        saySome()
    },2000);
}

function saySome() {
    console.log("Sending Some");
    socket.send("Some");
}



//当浏览器不支持websocket时，使用sockjs弥补
var url = 'localhost:8080/socket';
var socket = new SockJS(url);

socket.onclose = function (p1) {
    console.log("Close")
}

socket.onopen = function (event) {
    console.log("Open");
    // saySome();
}

socket.onmessage = function (p1) {
    console.log("Received:"+p1.data);
    setTimeout(function () {
        saySome()
    },2000);
}

function saySome() {
    console.log("Sending Some");
    socket.send("Some");
}


